package com.sanrenzu.everybodytv.ui.live;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.handmark.pulltorefresh.library.PullToRefreshGridView;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.sanrenzu.everybodytv.R;
import com.sanrenzu.everybodytv.bean.gy.LiveDataBean;

import java.util.List;

/**
 * Created by My on 2016/9/5.
 */
public class LiveFragment extends Fragment implements LiveContract.View{
    private PullToRefreshGridView pullToRefreshGridView_live;
    private Context mContext;
    private LiveContract.Presenter presenter;
    private LiveGridViewAdapter adapter;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext=getContext();
        presenter=new LivePresenter(this);
        presenter.getData();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_live,container,false);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
        initSetting();
    }

    private void initSetting() {
        //设置下拉加载动画
    }

    private void initView() {
        //初始化直播中GridView的控件
        pullToRefreshGridView_live=
                (PullToRefreshGridView) getActivity().findViewById(R.id.pullToRefreshGridView_live);
    }
    @Override
    public void onGetDataSuccess(List<LiveDataBean> list) {
        adapter=new LiveGridViewAdapter(mContext,list);
        pullToRefreshGridView_live.setAdapter(adapter);
    }

    @Override
    public void onGetDataFail(String error) {
        Toast.makeText(mContext, error, Toast.LENGTH_SHORT).show();
    }
}
